<?php
//登录数据接收。openid只是辅助登录
session_start();
require_once("../includes/public.inc.php");
$act = isset($_GET['act'])?$_GET['act']:'';
$type = isset($_GET['type'])?$_GET['type']:'';
$s = isset($_GET['s'])?$_GET['s']:'';
$user =  isset($_POST['user'])?trim($_POST['user']):'';
$password = isset($_POST['password'])?trim($_POST['password']):'';
if ($act=='login'&&$user&&$password)
{
	if ($type == 'dg')
	{
		$exsit_user = mysql_fetch_array(mysql_query("select * from ".DBQIAN."daogou where username='".$user."' and password='".$password."' order by id desc limit 1"));
	}
	else
	{
		$exsit_user = mysql_fetch_array(mysql_query("select * from ".DBQIAN."users where username='".$user."' and password='".$password."' order by id desc limit 1"));
	}
	if ($exsit_user)
	{
//		$_SESSION['username'] = $user;
//		$_SESSION['password'] = $password;
		//暂时不需要定义openid
		
		if ($type == 'dg')
		{
			$_SESSION['username'] = $exsit_user['username'];
			$_SESSION['password'] = $exsit_user['password'];
			if ($exsit_user['status'] == 0)
			{
				header("Location: check.php?s=".$s);exit;
			}
			if ($s)
			{
				$exsit_fwm = mysql_fetch_array(mysql_query("select * from ".DBQIAN."fwm where fwm='".$s."' and dgstatus=0 order by id desc limit 1"));
				if ($exsit_fwm)
				{	//如果没有领过
					header("Location: linghongbao.php?s=".$s);exit;
				}
				else 
				{
					//领过
					header("Location: index.php?s=".$s."&type=dg");exit;
				}
			}
			else 
			{
				//仅仅是登陆
				header("Location: index.php?type=dg");exit;
			}
		}
		else //普通用户
		{
			$_SESSION['username'] = $exsit_user['username'];
			$_SESSION['password'] = $exsit_user['password'];
			if ($s)
			{
				$exsit_fwm = mysql_fetch_array(mysql_query("select * from ".DBQIAN."fwm where fwm='".$s."' and hystatus=0 order by id desc limit 1"));
				
				if ($exsit_fwm)
				{
					header("Location: jifen.php?type=hy&s=".$s);exit;//如果登录成功没有领取的话，直接跳到领取页面
				}
				else 
				{
					header("Location: index.php?s=".$s."&type=hy");exit;
				}
			}
			else 
			{
				header("Location: index.php?type=hy");exit;
			}
		}
		
	}
	else 
	{
		echo "<script>alert('登录失败!');history.go(-1);</script>";exit;
	}
}
else 
{
	echo "<script>alert('请别乱穿越好吧！你的操作已经被记录！后果自负！');history.go(-1);</script>";exit;	
}

?>